#pragma once

#include "stdafx.h"

namespace natrium {
	namespace core {
		class Kernel;

		class Task
		{
		public:
			typedef std::shared_ptr<Task> TaskPtr;

			struct TaskBeginning {
				TaskBeginning(const TaskPtr& t);

				TaskPtr mTask;
			};

			struct TaskCompleted {
				TaskCompleted(const TaskPtr& t);

				TaskPtr mTask;
			};

			enum {
				//empty
				NONE = 0x0,

				//actual bit settings
				REPEATING = 0x1 << 0,
				THREADSAFE = 0x1 << 1,
				FRAME_SYNC = 0x1 << 2,

				//common combinations
				SINGLETHREADED = NONE,
				SINGLETHREADED_REPEATING = REPEATING,
				BACKGROUND = THREADSAFE,
				BACKGROUND_REPEATING = THREADSAFE | REPEATING,
				BACKGROUND_SYNC = THREADSAFE | FRAME_SYNC,
				BACKGROUND_REPEATING_SYNC = THREADSAFE | REPEATING | FRAME_SYNC,

				//every bit switched on
				ALL = ~0x0
			};

			Task(unsigned int flags = SINGLETHREADED_REPEATING);
			virtual ~Task();

			virtual void run() = 0;

		protected:
			friend class Kernel;

			void setTaskFlags(unsigned int newFlags);
			unsigned int getTaskFlags() const;

		private:
			unsigned int mTaskFlags;
		};
	}
}